using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Packtracker.Business;

namespace Packtracker.UserControls
{
	public partial class EnderecoListar : UserControl
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!IsPostBack)
			{
				ApplyAuthorizationRules();
			}
		}

		private void ApplyAuthorizationRules()
		{
			novoItemButton.Visible = Packtracker.Business.Endereco.CanAddObject();
		}


		#region LinkButton Novo    
		
		protected void novoItemButton_Click(object sender, EventArgs e)
		{
			Response.Redirect("EnderecoEditar.aspx");
		}
		
		#endregion
		
		#region GridView Endereco   
		
		protected void enderecoListDataSource_SelectObject(object sender, Csla.Web.SelectObjectArgs e)
		{
			e.BusinessObject = EnderecoCollection.GetEnderecoCollection();
		}

		protected void enderecoGrid_SelectedIndexChanged(object sender, EventArgs e)
		{
			Response.Redirect("~/EnderecoEditar.aspx" +
				"?Enderecoid=" + Server.UrlEncode(enderecoGrid.SelectedDataKey["id"].ToString()));
		}
		
		#endregion
	}
}
